﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using WHC.Hotel.BLL;
using WHC.OrderWater.Commons;


namespace WHC.Hotel.UI
{
    public partial class FrmTeaCaculate : BaseForm
    {
        public FrmTeaCaculate()
        {
            InitializeComponent();
        }

        private void BindData()
        {
            this.dgType.AutoGenerateColumns = false;
            this.dgType.DataSource = BLLFactory<TeaCaculteType>.Instance.GetAllToDataTable();
            this.dgType.Columns[0].DataPropertyName = "ID";
            this.dgType.Columns[1].DataPropertyName = "Name";
            this.dgType.Columns[2].DataPropertyName = "Price";  
        }

        private void FrmTeaCaculate_Load(object sender, EventArgs e)
        {
            BindData();
        }

        private void btnAddType_Click(object sender, EventArgs e)
        {
            FrmEditCaculate dlg = new FrmEditCaculate();
            if (DialogResult.OK == dlg.ShowDialog())
            {
                BindData();
            }
        }

        private void btnEditType_Click(object sender, EventArgs e)
        {
            foreach (DataGridViewRow row in this.dgType.SelectedRows)
            {
                FrmEditCaculate dlg = new FrmEditCaculate();
                dlg.ID = row.Cells[0].Value.ToString();
                if (DialogResult.OK == dlg.ShowDialog())
                {
                    BindData();
                }

                break;
            }
        }

        private void btnDeleteType_Click(object sender, EventArgs e)
        {
            if (MessageUtil.ShowYesNoAndTips("您确定删除选定的记录么？") == DialogResult.No)
            {
                return;
            }

            foreach (DataGridViewRow row in this.dgType.SelectedRows)
            {
                BLLFactory<TeaCaculteType>.Instance.Delete(row.Cells[0].Value.ToString());
                BindData();
            }
        }

        private void dgType_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
        {
            btnEditType_Click(null, null);
        }
    }
}
